﻿//*后台管理页JS函数，Jquery扩展
//*作者：xiaoshe
//*时间：2013年01月08日

$.ajaxSetup({
    cache: false
});

$(function () {
    //$('.aspNetHidden').hide();
    Loading(false);
    LoadCss();
    //$("#txt_Search").focus().select(); //搜索框默认焦点
});
/**
中间加载对话窗
**/
function Loading(bool) {
    if (bool) {
        top.$("#loading").show();
    } else {
        setInterval(LoadingHide, 800);
    }
}
function LoadingHide() {
    top.$("#loading").hide();
}
/**
Top 加载对话窗
msg:提示信息
time：停留时间ms
**/
function TopLoading(msg, time) {
    var _time = 1000;
    if (IsNullOrEmpty(time)) {
        _time = time;
    }
    top.$("#Toploading").show().html(msg);
    top.$('#Toploading').css("left", ($(window).width() - $("#Toploading").width()) / 2);
    setInterval(TopLoadingHide, _time);
}
function TopLoadingHide() {
    top.$("#Toploading").hide();
}

/**
短暂提示
msg: 显示消息
time：停留时间ms
type：类型 4：成功，5：失败，3：警告
**/
function ShowTipsMsg(msg, time, type) {
    top.ZENG.msgbox.show(msg, type, time);
}

function ShowWarningMsg(msg) {
    top.art.dialog({
        id: 'warningId',
        title: '系统提示',
        content: msg,
        icon: 'warning',
        time: 10,
        background: '#000',
        opacity: 0.1,
        lock: true,
        okVal: '关闭',
        ok: true
    });
}
/**
警告提示
msg: 显示消息
callBack：函数
**/
function ShowConfirmMsg(msg, callBack) {
    top.art.dialog({
        id: 'confirmId',
        title: '系统提示',
        content: msg,
        icon: 'warning',
        background: '#000000',
        opacity: 0.1,
        lock: true,
        button: [{
            name: '确定',
            callback: function () {
                callBack(true);
            },
            focus: true
        }, {
            name: '取消',
            callback: function () {
                this.close();
                return false;
            }
        }]
    });
}
/*弹出网页
/*url:          表示请求路径
/*_id:          ID
/*_title:       标题名称
/*width:        宽度
/*height:       高度
---------------------------------------------------*/
function OpenDialog(url, _id, _title, _width, _height, left, top) {
    art.dialog.open(url, {
        id: _id,
        title: _title,
        width: _width,
        height: _height,
        left: left + '%',
        top: top + '%',
        background: '#000000',
        opacity: 0.1,
        lock: true,
        resize: false,
        close: function () { }
    }, false);
}
//窗口关闭
function OpenClose() {
    art.dialog.close();
}
/*验证
/*id:        表示请求
--------------------------------------------------*/
function IsNullOrEmpty(str) {
    var isOK = true;
    if (str == undefined || str == "") {
        isOK = false;
    }
    return isOK;
}
/*数据放入回收站
/*url:        表示请求路径
/*parm：      条件参数
--------------------------------------------------*/

/* 请求Ajax 带返回值，并弹出提示框提醒
--------------------------------------------------*/
function Ajax(url, parm, callBack) {
    $.ajax({
        type: 'post',
        dataType: "text",
        url: url,
        data: parm,
        cache: false,
        async: false,
        success: function (msg) {
            callBack(msg);
        }
    });
}
/**
数据验证完整性
**/
function CheckDataValid(id) {
    if (!JudgeValidate(id)) {
        return false;
    } else {
        return true;
    }
}
/********
接收地址栏参数
key:参数名称
**********/
function GetQuery(key) {
    var search = location.search.slice(1); //得到get方式提交的查询字符串
    var arr = search.split("&");
    for (var i = 0; i < arr.length; i++) {
        var ar = arr[i].split("=");
        if (ar[0] == key) {
            return ar[1];
        }
    }
    return "";
}
/**iframe自应高度**/
function iframeresize(height) {
    if (height == undefined) {
        height = 0;
    }
    resizeU();
    $(window).resize(resizeU);
    function resizeU() {
        var iframeMain = $(window).height();
        $("#iframeMainContent").height(iframeMain - height);
    }
}
/**.div-body 自应表格高度**/
function divresize(height) {
    resizeU();
    $(window).resize(resizeU);
    function resizeU() {
        $(".div-body").css("height", $(window).height() - height);
    }
}
//Tab标签切换
function GetTabClick(e) {
    Loading(true);
    $("#menutab div").each(function () {
        this.className = "Tabremovesel";
    });
    e.className = "Tabsel";
    Loading(false);
}
/**
初始化样式
**/
function LoadCss() {
   
}
/*****************树形样式********************************/
function AutoTreeCss() {
    $('.strTree').lightTreeview({
        collapse: true,
        line: true,
        nodeEvent: false,
        unique: false,
        style: 'black',
        animate: 100,
        fileico: false,
        folderico: true
    });
    TreeCss();
}
function TreeCss() {
    $(".strTree li div").css("cursor", "pointer");
    $(".strTree li div").click(function () {
        if ($(this).attr('class') == "" || $(this).attr('class') == undefined) {
            $(".strTree li div").removeClass("collapsableselected");
            $(this).addClass("collapsableselected"); //添加选中样式
        }
    })
}
//=================右键菜单 start========================
eval(function (p, a, c, k, e, d) { e = function (c) { return (c < a ? '' : e(parseInt(c / a))) + ((c = c % a) > 35 ? String.fromCharCode(c + 29) : c.toString(36)) }; if (!''.replace(/^/, String)) { while (c--) { d[e(c)] = k[c] || e(c) } k = [function (e) { return d[e] }]; e = function () { return '\\w+' }; c = 1 }; while (c--) { if (k[c]) { p = p.replace(new RegExp('\\b' + e(c) + '\\b', 'g'), k[c]) } } return p }('(4(a){4 b(){6 G}a.1O.10=4(l){l=a.1N({9:"1a",X:1P},l);3 q=8,z=8,u={},y={},i={},p=[],t="<N 1Q=\'b-m-$[R]\' O=Q><1i O=Q><1R 1M=\'$[1L]\' 1H=\'1G\'/><16 O=Q>$[1b]</16></1i></N>";3 k=a("<N/>").12("b-m-1I").1o("O","Q").19("17","1j");3 j=a("<N/>").12("b-m-Y").1o("O","Q");3 h=a("<N/>").12("b-m-1K");3 s=4(A){u[A.9]=2;2.H=A.9;2.1S=A.9;5(A.7){2.7=A.7;2.I="b-m-Z"}a(2).X(A.X).1m(b).1e(b).21(a("1d"));A=8;6 2};3 g=4(B){3 A=2;A.24=B.1b;A.T=B.9;A.H=B.H;A.20=B;A.1Z=t.1W(/\\$\\[([^\\]]+)\\]/g,4(){6 B[1c[1]]});5(B.7){A.7=B.7;A.I="b-m-Z"}B.K&&(A.V=1n);B.1g&&(i[B.9]=B.1g);y[B.9]=A;A=B=8;6 2};3 m=4(D,A){3 C=8;U(3 B=0;B<A.W;B++){5(A[B].R=="1Y"){C=h.P()[0]}11{A[B].H=D;5(A[B].R=="V"){s.S(k.P()[0],[A[B]]);1c.1y(A[B].9,A[B].K);A[B].R="1t";C=g.S(j.P()[0],[A[B]])}11{A[B].R="1E";C=g.S(j.P()[0],[A[B]]);a(C).1m(4(E){5(!2.7){5(a.15(i[2.T])){i[2.T].M(2,z)}c()}6 G})}a(C).1l("10",b).1u(o,v)}u[D].1r(C);C=A[B]=A[B].K=8}D=A=8};3 o=4(B){5(2.7){6 G}c.M(u[2.H]);5(2.V){3 C=a(2).1q();3 A=a(2).1k();e.S(u[2.T],[C,A])}2.I="b-m-1D";6 G};3 v=4(A){5(2.7){6 G}5(!2.V){2.I="b-m-Y"}6 G};3 e=4(F,C){3 E=a("1d").X();3 B=18.1A.1v;3 D=a(2).1k();3 A=a(2).1x();F.L=(F.L+C+D>E)?(F.L-D<0?0:F.L-D):F.L+C;F.J=(F.J+A>B)?(F.J-A+(C>0?25:0)<0?0:F.J-A+(C>0?25:0)):F.J;a(2).19(F).1B();p.1z(2.H)};3 c=4(){3 B=8;U(3 A=p.W-1;A>=0;A--){5(p[A]==2.H){1C}B=p.1w();u[B].1s.17="1j";y[B]&&(y[B].I="b-m-Y")}};4 f(B){5(q&&q==B.1f){6 G}U(3 A 26 y){d(A,!B.7)}U(3 A=0;A<B.K.W;A++){d(B.K[A],B.7)}q=B.1f}4 d(A,B){3 C=y[A];C.I=(C.7=C.1U.1V=B)?"b-m-Z":"b-m-Y"}4 n(A,B){z=B;e.M(u.1a,{L:A.23,J:A.1F},0);a(18).22("1e",c)}3 w=a("#"+l.9);3 r=8;5(w.W==0){r=s.S(k.P()[0],[l]);r.1T=f;r.1p=n;m(l.9,l.K)}11{r=w[0]}3 x=a(2).1J(4(){6 a(2).1l("10",4(B){3 A=(l.13&&a.15(l.13))?l.13.M(2,B):1n;5(A){5(l.14&&a.15(l.14)){l.14.M(2,r)}r.1p(B,2)}6 G})});5(l.1h){f(l.1h)}k=j=h=t=s=g=8;m=o=v=8;6 x}})(1X);', 62, 131, '||this|var|function|if|return|disable|null|alias|||||||||||||||||||||||||||||||||false|gidx|className|top|items|left|call|div|unselectable|clone|on|type|apply|idx|for|group|length|width|item|idisable|contextmenu|else|addClass|onContextMenu|onShow|isFunction|span|display|document|css|cmroot|text|arguments|body|mousedown|name|action|rule|nobr|none|outerWidth|bind|click|true|attr|showMenu|offset|appendChild|style|arrow|hover|clientHeight|pop|outerHeight|callee|push|documentElement|show|break|ifocus|ibody|pageY|absmiddle|align|mpanel|each|split|icon|src|extend|fn|150|class|img|id|applyrule|lastChild|disabled|replace|jQuery|splitLine|innerHTML|data|appendTo|one|pageX|title||in'.split('|'), 0, {}))


//=================动态菜单tab标签========================
// IsReplace：是否允许关闭 url：打开链接 
function AddTabMenu(tabid, url, name, img, Isclose, IsReplace) {
    if (url == "" || url == "#") {
        url = "/ErrorPage/404.aspx";
    }
    var tabs = top.$("#tabs_container");//标签容器
    var contentPannel = top.$("#ContentPannel");//标签iframe内容容器
    if (IsReplace == 'true') {
        top.CloseTab(tabid);
    }
    if (top.document.getElementById("tabs_" + tabid) == null) {
        if (contentPannel.find('iframe').length > 8) {
            ShowWarningMsg("标签页打开过多，请关闭其它标签！");
            return;
        }
        Loading(true);
        tabs.find('li').removeClass('selected');
        contentPannel.find('iframe').hide();
        if (Isclose != 'false') { //判断是否带关闭tab
            tabs.append("<li id=\"tabs_" + tabid + "\" class='selected' win_close='true'><span title='" + name + "' onclick=\"javascript:AddTabMenu('" + tabid + "','" + url + "','" + name + "','" + img + "','true')\"><a href=\"javascript:;\"><img src=\"/Themes/Images/" + img + "\" width=\"20\" height=\"20\">" + name + "</a></span><a class=\"win_close\" title=\"关闭当前窗口\" onclick=\"CloseTab('" + tabid + "')\"></a></li>");
        } else {
            tabs.append("<li id=\"tabs_" + tabid + "\" class=\"selected\" onclick=\"javascript:AddTabMenu('" + tabid + "','" + url + "','" + name + "','" + img + "','false')\"><a><img src=\"/Themes/Images/" + img + "\" width=\"20\" height=\"20\">" + name + "</a></li>");
        }
        contentPannel.append("<iframe id=\"div_" + tabid + "\"  name=\"div_" + tabid + "\" height=\"100%\" width=\"100%\" src=\"" + url + "\" frameBorder=\"0\"></iframe>");
        //右键菜单
        $("#tabs_" + tabid).contextmenu(Menu());
    }
    else {//如果当前tabid存在直接显示已经打开的tab
        tabs.find('li').removeClass('selected');
        contentPannel.find('iframe').hide();
        tabs.find('#tabs_' + tabid).addClass('selected');
        top.document.getElementById("div_" + tabid).style.display = 'block';
    }
}
//关闭标签
function CloseTab(obj) {
    var tabs = top.$("#tabs_container");
    var contentPannel = top.$("#ContentPannel");

    tabs.find("#tabs_" + obj).remove();
    contentPannel.find("#div_" + obj).remove();
    var tablist = tabs.find('li');
    var pannellist = contentPannel.find('iframe');
    if (tablist.length > 0) {
        tablist[tablist.length - 1].className = 'selected';
        pannellist[tablist.length - 1].style.display = 'block';
    }
    if (tablist.length == '1') {
        top.$(".navigation").show();
    }
}
//最大化
function Maximize() {
    $("#Content").addClass("ContentMaximize");
    $("#fullreturn").show();
    top.$("#Header,.navigation,#Headerbotton").hide();//头部 左侧菜单 顶部菜单
    TopLoading('注意：要还原，请单击右上角的红色按钮。', 3000)
}
//还原 判断变量是否定义typeof (main) != "undefined"
function Fullrestore() {
    $("#Content").removeClass("ContentMaximize");
    $("#fullreturn").hide();
    // 2014-07-08
    top.$("#Header,.navigation,#Headerbotton").show();//头部 左侧菜单 顶部菜单
}

/*
刷新当前模块窗口（主页或当前标签） 2014-07-08 
*/
function RefreshCurrentModule() {
    try {
        var id = CurrentIframeID();
        //top.$('#' + CurrentIframeID())[0].contentWindow.target_right.windowload();// 刷新target_right
        top.$('#' + id)[0].contentWindow.windowload();
    } catch (e) { }
}
/*
获取当前tab标签的iframeId
*/
function CurrentIframeID() {
    var tabs_container = top.$("#tabs_container");
    return "div_" + tabs_container.find('.selected').attr('id').substr(5);
}
//=================动态菜单tab标签 end========================

//=================PQ公共方法 start========================

/**
加载表格函数
gridID:元素ID, url:请求地址, colM:表头, fields:要显示字段, topVisible: , PageSize：每页大小 , editable:表格是否可编辑 , sortIndex:排序列索引
**/
var currentRow = -1;//当前选中行索引
/**
加载表格函数 无分页
gridID:元素ID, url:请求地址, colM:表头, fields:要显示字段, topVisible: , PageSize：每页大小 , editable:表格是否可编辑 , sortIndex:排序列索引
**/
function PQListNoPage(gridID, url, colM, fields, editable) {
    currentRow = -1;
    var dataModel = {
        location: "remote",
        sorting: "remote",
        paging: "",
        dataType: "JSON",
        method: "GET",
        sortIndx: 0,
        sortDir: "up",
        getUrl: function () {
            var orderField = (this.sortIndx == "0") ? "" : fields[this.sortIndx];
            var sortDir = (this.sortDir == "up") ? "desc" : "asc";
            return {
                url: url,
                data: "pqPageIndex=" + orderField + "&pqOrderType=" + sortDir + "&pqFields=" + escape(fields)
            };
        },
        getData: function (dataJSON) {
            if (dataJSON == null) {
                ShowTipsMsg("没有找到您要的相关数据！", 5000, 5);
            }
            return { data: dataJSON };
        }
    }
    $(gridID).pqGrid({
        dataModel: dataModel,
        colModel: colM,
        editable: editable == null ? false : editable,
        bottomVisible: false,
        oddRowsHighlight: false,
        columnBorders: true,
        freezeCols: 0,
        rowSelect: function (evt, ui) {
            currentRow = ui.rowIndxPage;
        }
    });
    PQResize(gridID, -36, -4);
}
/**
表格自应高度
obj：ID，lose_height:-高度,lose_width:-宽度
**/
function PQResize(obj, lose_height, lose_width) {
    var height = $(window).height() + lose_height;
    var width = $(window).width() + lose_width;
    var grid1 = $(obj).pqGrid({
        width: width,
        height: height
    });
}
//=================PQ公共方法 end========================
